package buaa.com.util;

import android.database.Cursor;
import android.util.Log;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/4/25.
 */
public class CrazyDao {
    public static List<Map<String, Object>> getStageData(int nowStage) {
        List<Map<String, Object>> values = new ArrayList<>();
        String sql = "select id from crazy";
        Cursor c = Globals.util.getReadableDatabase().rawQuery(sql,null);
        c.moveToFirst();
        //Log.d("nowStage-values...", nowStage + "........................................" + c.isAfterLast());
        while(!c.isAfterLast()) {
            Map<String, Object> map = new HashMap<>();
            map.put("stage", c.getInt(0));
            if(nowStage>=c.getInt(0)) {
                map.put("overFlag", true);
            }else {
                map.put("overFlag", false);
            }
            values.add(map);
            c.moveToNext();
        }
        c.close();
        //Log.d("nowStage-values...", nowStage + "........................................"+values.size());
        return values;
    }
    public static Map<String,Object> getDataByid(int id){
        String sql = "select question_type, answer, question_img, select_txt from crazy where id = ?";
        Map<String,Object> map = new HashMap<>();
        Cursor c = Globals.util.getReadableDatabase().rawQuery(sql,new String[]{String.valueOf(id)});
        c.moveToFirst();
        Log.d("aqqs",c.getString(0)+","+c.getString(1)+","+c.getString(2)+","+c.getString(3));
        map.put("questionType", c.getString(0));
        map.put("answer", c.getString(1));
        map.put("questionImg", c.getString(2));
        map.put("selectTxt", c.getString(3));
        c.close();
        return map;

    }
}
